const ffmpeg = require('fluent-ffmpeg')
const chalk = require('chalk')
const fs = require('fs')
const outputDir = fs.readdirSync('./output/')
const fileName = outputDir.length + 1
let t = 0
const timer = setInterval(() => {
  t++
}, 1000)
ffmpeg()
  .input(`./${fileName}/video.m4s`)
  .input(`./${fileName}/audio.m4s`)
  .on('start', function (commandLine) {
    console.log(chalk.yellow(`running...${commandLine}`))
  })
  .on('error', function (err, stdout, stderr) {
    console.log('Cannot process video: ' + chalk.red(err.message))
  })
  .on('end', function () {
    clearInterval(timer)
    console.log('Finished Total: ' + chalk.green(t + 's'))
  })
  .save(`./output/${fileName}.mp4`)
